#include "Shared.fxh"

float4 light_d1_vs(
	float4 iPos : POSITION,
	float3 iNorm : NORMAL,
	float2 iTc : TEXCOORD0,
	
	out float2 oTc : TEXCOORD0,
	out float3 oNorm : TEXCOORD1,
	out float3 oEye : TEXCOORD2
	) : POSITION
{
	oTc = iTc;
	oNorm = mul( iNorm, (float3x3)MatModelView );
	oEye = mul( iPos, MatModelView ).xyz;
	
	return mul( iPos, MatMvp );
}

const float3 lDirection = float3( 0, 0, 1 );
const float4 lDiffuse = float4( 0.5, 0.5, 0.5, 1 );
const float4 lSpecular = float4( 0.5, 0.5, 0.5, 1 );

float4 light_d1_ps(
	float2 iTc : TEXCOORD0,
	float3 iNorm : TEXCOORD1,
	float3 iEye : TEXCOORD2
	) : COLOR0
{
	float3 n = normalize( iNorm );
	float3 e = -normalize( iEye );
	float3 h = normalize( e + lDirection );
	
	float ndl = dot( n, lDirection );
	float ndh = dot( n, h );

	float4 l = lit( ndl, ndh, 50 );
	
	float4 baseCl = float4( 0.5 + frac( iTc ) * 0.3, 0.5, 1 );
	return baseCl * lDiffuse * saturate( 0.3 + l.y ) + lSpecular * 0.6 * l.z;
}

technique t0
{
	pass light_amb
	{
		VertexShader = compile vs_2_0 light_d1_vs();
		PixelShader = compile ps_2_0 light_d1_ps();
		
		AlphaBlendEnable = False;
		AlphaTestEnable = False;
		ZEnable = True;
		ZFunc = LessEqual;
		ZWriteEnable = True;
	}
}